{
 "cells": [
  {
   "cell_type": "markdown",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "This is an example tutorial to generate a training dataset from scratch.\n",
    "\n",
    "The example here creates the first dialog from the dstc2 train dataset, but in a similar fashion, you can create any dataset that fits your purpose.\n",
    "\n",
    "To start, you will need:\n",
    "1. dstc2 type template file. See the downloaded dstc2-templates.txt for a reference. You can create a new one with your own templates\n",
    "2. slot values that you need to provide in a JSON format. See dstc_slot_vals.json as a reference\n",
    "3. An sqlite database instance with a table that matches 1 and 2 above. Spend some time to see how these two relate to the database. Again, downloaded db.sqlite is a good starting poin.\n",
    "\n",
    "Once you have these, you are set to start your own dataset generation\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install deeppavlov\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "from deeppavlov.contrib import examples\n",
    "from deeppavlov.contrib.data.tools.train_set_generation import TrainSetGeneration\n",
    "\n",
    "template_fn = \"dstc2-templates.txt\"\n",
    "slot_fn = \"dstc_slot_vals.json\"\n",
    "db_fn = \"db.sqlite\"\n",
    "\n",
    "template_path = os.path.join(examples.__path__._path[0], template_fn)\n",
    "slot_path = os.path.join(examples.__path__._path[0], slot_fn)\n",
    "db_path = os.path.join(examples.__path__._path[0], db_fn)\n",
    "\n",
    "trainsetgen = TrainSetGeneration(template_path = template_path,\n",
    "                                 slot_path = slot_path,\n",
    "                                 save_path = \"generated_data.json\",\n",
    "                                 db_path = db_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n",
      "type template number from the list: 45\n",
      "[INFO] generated response is:  Hello, welcome to the Cambridge restaurant system. You can ask for restaurants by area, price range or food type. How may I help you?\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): cheap restaurant\n",
      "[INFO] please enter integer value\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 1\n",
      "\n",
      "**********\n",
      "[INFO] write a user sentence: cheap restaurant\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if your sentence has a slot, else 0: 1\n",
      "0 phone\n",
      "1 postcode\n",
      "2 this\n",
      "3 name\n",
      "4 addr\n",
      "5 food\n",
      "6 area\n",
      "7 pricerange\n",
      "\n",
      "**********\n",
      "[INPUT] type slot category number from the list: 7\n",
      "0 moderate\n",
      "1 expensive\n",
      "2 cheap\n",
      "3 dontcare\n",
      "\n",
      "**********\n",
      "[INPUT] type slot subcategory number from the list: 2\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if you want to add more slots, else 0: 0\n",
      "{'speaker': 1, 'text': 'cheap restaurant', 'slots': [['pricerange', 'cheap']]}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap'}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n",
      "type template number from the list: 40\n",
      "[INFO] generated response is:  What kind of food would you like?\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 1\n",
      "\n",
      "**********\n",
      "[INFO] write a user sentence: any\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if your sentence has a slot, else 0: 1\n",
      "0 phone\n",
      "1 postcode\n",
      "2 this\n",
      "3 name\n",
      "4 addr\n",
      "5 food\n",
      "6 area\n",
      "7 pricerange\n",
      "\n",
      "**********\n",
      "[INPUT] type slot category number from the list: 2\n",
      "0 dontcare\n",
      "\n",
      "**********\n",
      "[INPUT] type slot subcategory number from the list: 0\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if you want to add more slots, else 0: 0\n",
      "{'speaker': 1, 'text': 'any', 'slots': [['this', 'dontcare']]}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap', 'this': 'dontcare'}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n",
      "type template number from the list: 39\n",
      "[INFO] generated response is:  What part of town do you have in mind?\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 1\n",
      "\n",
      "**********\n",
      "[INFO] write a user sentence: south\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if your sentence has a slot, else 0: 1\n",
      "0 phone\n",
      "1 postcode\n",
      "2 this\n",
      "3 name\n",
      "4 addr\n",
      "5 food\n",
      "6 area\n",
      "7 pricerange\n",
      "\n",
      "**********\n",
      "[INPUT] type slot category number from the list: 6\n",
      "0 south\n",
      "1 east\n",
      "2 dontcare\n",
      "3 north\n",
      "4 west\n",
      "5 centre\n",
      "\n",
      "**********\n",
      "[INPUT] type slot subcategory number from the list: 0\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if you want to add more slots, else 0: 0\n",
      "{'speaker': 1, 'text': 'south', 'slots': [['area', 'south']]}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap', 'this': 'dontcare', 'area': 'south'}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "type template number from the list: 0\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO in 'deeppavlov.models.go_bot.tracker.dialogue_state_tracker'['dialogue_state_tracker'] at line 102: Made api_call with {'area': 'south', 'pricerange': 'cheap'}, got 2 results.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[INFO] generated response is:  Api_call area=\"south\" food=\"#food\" pricerange=\"cheap\"\tapi_call area=\"south\" food=\"#food\" pricerange=\"cheap\"\n",
      "[INFO] the result of the db call is:  {'food': 'chinese', 'pricerange': 'cheap', 'area': 'south', 'postcode': 'c.b 1, 7 d.y', 'phone': '01223 244277', 'addr': 'cambridge leisure park clifton way cherry hinton', 'name': 'the lucky star'}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap', 'this': 'dontcare', 'area': 'south'}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n",
      "type template number from the list: 23\n",
      "[INFO] generated response is:  The lucky star is a nice place in the south of town serving tasty chinese food.\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 1\n",
      "\n",
      "**********\n",
      "[INFO] write a user sentence: address\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if your sentence has a slot, else 0: 1\n",
      "0 phone\n",
      "1 postcode\n",
      "2 this\n",
      "3 name\n",
      "4 addr\n",
      "5 food\n",
      "6 area\n",
      "7 pricerange\n",
      "\n",
      "**********\n",
      "[INPUT] type slot category number from the list: 4\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if you want to add more slots, else 0: 0\n",
      "{'speaker': 1, 'text': 'address', 'slots': [['addr', '']]}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap', 'this': 'dontcare', 'area': 'south', 'addr': ''}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n",
      "type template number from the list: 21\n",
      "[INFO] generated response is:  Sure, the lucky star is on cambridge leisure park clifton way cherry hinton.\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 1\n",
      "\n",
      "**********\n",
      "[INFO] write a user sentence: phone number\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if your sentence has a slot, else 0: 1\n",
      "0 phone\n",
      "1 postcode\n",
      "2 this\n",
      "3 name\n",
      "4 addr\n",
      "5 food\n",
      "6 area\n",
      "7 pricerange\n",
      "\n",
      "**********\n",
      "[INPUT] type slot category number from the list: 0\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if you want to add more slots, else 0: 0\n",
      "{'speaker': 1, 'text': 'phone number', 'slots': [['phone', '']]}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap', 'this': 'dontcare', 'area': 'south', 'addr': '', 'phone': ''}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n",
      "type template number from the list: 32\n",
      "[INFO] generated response is:  The phone number of the lucky star is 01223 244277.\tThe phone number of the lucky star is dontcare.\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 1\n",
      "\n",
      "**********\n",
      "[INFO] write a user sentence: thank you good bye\n",
      "\n",
      "**********\n",
      "[INPUT] type 1 if your sentence has a slot, else 0: 0\n",
      "{'speaker': 1, 'text': 'thank you good bye', 'slots': []}\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 2\n",
      "\n",
      "**********\n",
      "[INFO] current slot vals are:  {'pricerange': 'cheap', 'this': 'dontcare', 'area': 'south', 'addr': '', 'phone': ''}\n",
      "0 api_call\n",
      "1 bye\n",
      "2 canthear\n",
      "3 canthelp_area\n",
      "4 canthelp_area_food\n",
      "5 canthelp_area_food_pricerange\n",
      "6 canthelp_area_pricerange\n",
      "7 canthelp_food\n",
      "8 canthelp_food_pricerange\n",
      "9 confirm-domain\n",
      "10 expl-conf_area\n",
      "11 expl-conf_food\n",
      "12 expl-conf_pricerange\n",
      "13 impl-conf_area+impl-conf_pricerange+request_food\n",
      "14 impl-conf_food+impl-conf_pricerange+request_area\n",
      "15 impl-conf_food+request_area\n",
      "16 inform_addr+inform_food+offer_name\n",
      "17 inform_addr+inform_phone+inform_pricerange+offer_name\n",
      "18 inform_addr+inform_phone+offer_name\n",
      "19 inform_addr+inform_postcode+offer_name\n",
      "20 inform_addr+inform_pricerange+offer_name\n",
      "21 inform_addr+offer_name\n",
      "22 inform_area+inform_food+inform_pricerange+offer_name\n",
      "23 inform_area+inform_food+offer_name\n",
      "24 inform_area+inform_phone+offer_name\n",
      "25 inform_area+inform_postcode+offer_name\n",
      "26 inform_area+inform_pricerange+offer_name\n",
      "27 inform_area+offer_name\n",
      "28 inform_food+inform_pricerange+offer_name\n",
      "29 inform_food+offer_name\n",
      "30 inform_phone+inform_postcode+offer_name\n",
      "31 inform_phone+inform_pricerange+offer_name\n",
      "32 inform_phone+offer_name\n",
      "33 inform_postcode+inform_pricerange+offer_name\n",
      "34 inform_postcode+offer_name\n",
      "35 inform_pricerange+offer_name\n",
      "36 offer_name\n",
      "37 repeat\n",
      "38 reqmore\n",
      "39 request_area\n",
      "40 request_food\n",
      "41 request_pricerange\n",
      "42 select_area\n",
      "43 select_food\n",
      "44 select_pricerange\n",
      "45 welcomemsg\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "type template number from the list: 1\n",
      "[INFO] generated response is:  You are welcome!\n",
      "\n",
      "**********\n",
      "[INPUT] choose turn (1 for user, 2 for bot, 3 to start a new dialog or 10 for saving and exit): 10\n",
      "\n",
      "**********\n",
      "[INFO] saving the dialogs and exiting...\n"
     ]
    }
   ],
   "source": [
    "trainsetgen.start_generation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "with open(trainsetgen.save_path) as f:\n",
    "    dialogs = json.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[   [   {   'act': 'welcomemsg',\n",
      "            'slots': [],\n",
      "            'speaker': 2,\n",
      "            'text': 'Hello, welcome to the Cambridge restaurant system. You '\n",
      "                    'can ask for restaurants by area, price range or food '\n",
      "                    'type. How may I help you?'},\n",
      "        {   'slots': [['pricerange', 'cheap']],\n",
      "            'speaker': 1,\n",
      "            'text': 'cheap restaurant'},\n",
      "        {   'act': 'request_food',\n",
      "            'slots': [],\n",
      "            'speaker': 2,\n",
      "            'text': 'What kind of food would you like?'},\n",
      "        {'slots': [['this', 'dontcare']], 'speaker': 1, 'text': 'any'},\n",
      "        {   'act': 'request_area',\n",
      "            'slots': [],\n",
      "            'speaker': 2,\n",
      "            'text': 'What part of town do you have in mind?'},\n",
      "        {'slots': [['area', 'south']], 'speaker': 1, 'text': 'south'},\n",
      "        {   'act': 'api_call',\n",
      "            'db_result': '{\"food\": \"chinese\", \"pricerange\": \"cheap\", \"area\": '\n",
      "                         '\"south\", \"postcode\": \"c.b 1, 7 d.y\", \"phone\": \"01223 '\n",
      "                         '244277\", \"addr\": \"cambridge leisure park clifton way '\n",
      "                         'cherry hinton\", \"name\": \"the lucky star\"}',\n",
      "            'slots': [   ['area', 'south'],\n",
      "                         ['pricerange', 'cheap'],\n",
      "                         ['area', 'south'],\n",
      "                         ['pricerange', 'cheap']],\n",
      "            'speaker': 2,\n",
      "            'text': 'Api_call area=\"south\" food=\"#food\" pricerange=\"cheap\"\\t'\n",
      "                    'api_call area=\"south\" food=\"#food\" pricerange=\"cheap\"'},\n",
      "        {   'act': 'inform_area+inform_food+offer_name',\n",
      "            'slots': [   ['area', 'south'],\n",
      "                         ['name', 'the lucky star'],\n",
      "                         ['area', 'south'],\n",
      "                         ['food', 'chinese']],\n",
      "            'speaker': 2,\n",
      "            'text': 'The lucky star is a nice place in the south of town '\n",
      "                    'serving tasty chinese food.'},\n",
      "        {'slots': [['addr', '']], 'speaker': 1, 'text': 'address'},\n",
      "        {   'act': 'inform_addr+offer_name',\n",
      "            'slots': [   ['name', 'the lucky star'],\n",
      "                         [   'addr',\n",
      "                             'cambridge leisure park clifton way cherry '\n",
      "                             'hinton']],\n",
      "            'speaker': 2,\n",
      "            'text': 'Sure, the lucky star is on cambridge leisure park clifton '\n",
      "                    'way cherry hinton.'},\n",
      "        {'slots': [['phone', '']], 'speaker': 1, 'text': 'phone number'},\n",
      "        {   'act': 'inform_phone+offer_name',\n",
      "            'slots': [   ['name', 'the lucky star'],\n",
      "                         ['phone', '01223 244277'],\n",
      "                         ['name', 'the lucky star']],\n",
      "            'speaker': 2,\n",
      "            'text': 'The phone number of the lucky star is 01223 244277.\\tThe '\n",
      "                    'phone number of the lucky star is dontcare.'},\n",
      "        {'slots': [], 'speaker': 1, 'text': 'thank you good bye'},\n",
      "        {'act': 'bye', 'slots': [], 'speaker': 2, 'text': 'You are welcome!'}]]\n"
     ]
    }
   ],
   "source": [
    "from pprint import pprint\n",
    "\n",
    "pprint(dialogs, indent=4)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}